package cn.com.bod.fas.common.annotation.validator;

import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

/**
 * @description 手机号校验规则
 * @author chenyuanxian
 * @date 2019年10月11日 10:56:52
 * @version 1.0.0
 * @Copyright (c) scfhdt
 */
public class MobileNumValidator implements ConstraintValidator<MobileNum, String> {
    

    private Pattern pattern = Pattern.compile("1(([38]\\d)|(5[^4&&\\d])|(4[579])|(7[0135678]))\\d{8}");
    
    @Override
    public void initialize(MobileNum constraintAnnotation) {
        
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (StringUtils.isBlank(value)) {
            return true;
        }
        return pattern.matcher(value).matches();
    }

}
